package com.shelpe.services.sinbad.repository.jpa;

import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.transaction.annotation.Transactional;

import com.shelpe.services.sinbad.entity.jpa.ExpertDistribution;

public interface ExpertDistributionRepository extends PagingAndSortingRepository<ExpertDistribution, Long> {

	List<ExpertDistribution> findByUserID(long userID);

	ExpertDistribution findByUserIDAndExpertID(long userID, long expertID);

	@Transactional
	@Modifying
	@Query(value = "insert into expert_distribution(user_id, nick,expert_name,content,is_apply,img,star,expert_id) "
			+ "select user_id,nick,?,?,?,?,?,? from users where user_type =1", nativeQuery = true)
	int deliver2experts(String expertName, String content, int isApply, String img, int star, long expertID);

	@Transactional
	@Modifying
	@Query(value = "insert into expert_distribution(user_id, nick,expert_name,content,is_apply,img,star,expert_id) "
			+ "select user_id,nick,?,?,?,?,?,? from users where user_type =1 and user_id=?", nativeQuery = true)
	int deliver2newUser(String expertName, String content, int isApply, String img, int star, long expertID,
			long userID);
}
